﻿using System;
using System.Web.Mvc;
using AutoMapper;
using Common.Views;
using Sanelib.DataView;
using WebApp.Services;

namespace WebApp.Controllers
{
    public class AttachmentController : SmartController
    {

        private readonly IViewRepository<AttachmentView> _attachmentViewRepository;
        public AttachmentController(IUserSession userSession, IMappingEngine mappingEngine, IViewRepository<AttachmentView> attachmentViewRepository)
            : base(userSession, mappingEngine)
        {
            _attachmentViewRepository = attachmentViewRepository;
        }

        public ActionResult Index(Guid id)
        {
            var view = _attachmentViewRepository.GetById(id);
            var result = new FileContentResult(view.FileData, view.FileType) {FileDownloadName = view.Name};
            return result;
        }       
    }
}
